from PyQt5 import QtWidgets
from util import popup_window_ui
import sys
import io
import qrcode
import base64


class PopupQrcode(popup_window_ui.Ui_Object):

    def __init__(self, popup_window, previous_window, b64str):
        qr_img = qrcode.make(
            'https://cloud1-6gsirie264f09323-1307670777.tcloudbaseapp.com/jump_mp.html?token_id=6914868034646466560&mer_order_no=22033017361573413931&order_amt=216.000')
        byte_io = io.BytesIO()
        qr_img.save(byte_io, 'PNG')
        byte_io.seek(0)
        base64_data = base64.b64encode(byte_io.getvalue())
        right_base64 = str(base64_data, 'utf-8')
        super().setupUi(popup_window)
        self.popup_window = popup_window
        self.previous_window = previous_window
        self.label.setText(
            f"<html><head/><body><p align=\"center\"><img src=\"data:image/png;base64,{right_base64}\"/></p></body></html>"
        )


if __name__ == "__main__":
    app = QtWidgets.QApplication(sys.argv)
    popup_window = QtWidgets.QMainWindow()
    popup_window_ui = PopupQrcode(popup_window, '')
    popup_window.setFixedSize(popup_window.width(), popup_window.height())
    popup_window.show()
    sys.exit(app.exec_())
